<!DOCTYPE html>
<html lang="en">
<head>
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height">
  <meta charset="UTF-8">
  <meta name="Author" content="haley">
  <meta name="Keywords" content="前端最常用的UI插件">
  <meta name="Description" content="最常用的UI插件">
  <script crossorigin="anonymous" integrity="sha384-6ePHh72Rl3hKio4HiJ841psfsRJveeS+aLoaEf3BWfS+gTF0XdAqku2ka8VddikM" src="https://lib.baomitu.com/jquery/1.11.3/jquery.min.js"></script>
  <link crossorigin="anonymous" integrity="sha384-pdapHxIh7EYuwy6K7iE41uXVxGCXY0sAjBzaElYGJUrzwodck3Lx6IE2lA0rFREo" href="https://lib.baomitu.com/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
  <link href="../../../css/page.css" rel="stylesheet">
  <script crossorigin="anonymous" integrity="sha384-pPttEvTHTuUJ9L2kCoMnNqCRcaMPMVMsWVO+RLaaaYDmfSP5//dP6eKRusbPcqhZ" src="https://lib.baomitu.com/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script crossorigin="anonymous" integrity="sha384-8t+aLluUVnn5SPPG/NbeZCH6TWIvaXIm/gDbutRvtEeElzxxWaZN+G/ZIEdI/f+y" src="https://lib.baomitu.com/vue/2.6.10/vue.min.js"></script>
  <script src="../../../js/page.js"></script>
  <script src="../../../js/changeTitle.js"></script>
  <link href="../../../imgs/favicon.ico" rel="shortcut icon">
  <script src="../../../js/goToHome.js"></script>
  <!--核心文件 s-->
  <!--核心文件 e-->
  <title></title>
  <script>
    var data={
      title:'数字跑秒特效',
      content:{
        intro:{
          list:[
            {
              title:'使用说明：',
              className:'bs-callout-info',
              list:[
                {title:'基础配置：',content:'jquery/1.11.3'}
                ,{title:'使用说明：',content:'页面滚动的时候，可是出现特效，scrollTop达处于min和max范围内时，进行滚动；web和wap可以单独设置'}
                ,{title:'需要的文件及代码：',content:'直接复制使用'}
                ,{title:'api：',content:"var numbers=[33,113,168,98]; pc:{'min':50,'max':100},wap:{'min':150,'max':250},"}
              ]
            }
          ]
        }
      }
    };
  </script>
</head>
<body>
<div id="page">
  <div class="container">
    <h3 class="text-center">{{title}}</h3>
    <div class="bs-callout" :class="item.className" v-for="item in content.intro.list">
      <h4>{{item.title}}</h4>
      <ul>
        <li v-for="item2 in item.list"><b>{{item2.title}}</b>{{item2.content}}</li>
      </ul>
    </div>
  </div>
  <script>
    var page = new Vue({
      el: '#page',
      data: data
    });
  </script>
</div>

<div class="container">
  <section class="panel panel-info">
    <div class="panel-heading">数字跑秒特效</div>
    <div class="panel-body">
<div>

  <h2>
    <span class="num1">33</span>
    <span class="num2">113</span>
    <span class="num3">168</span>
    <span class="num4">98</span>
  </h2>
  <script>
    /* 主控程序 */
    var w = $(window).width();//当前显示器宽度
    var SCREENlLIMIT=767;
    <!--奔跑数字-->
    var numbers=[33,113,168,98];

    var cons=[
      {"name":$('.num1'),"n":numbers[0]},
      {"name":$('.num2'),"n":numbers[1]},
      {"name":$('.num3'),"n":numbers[2]},
      {"name":$('.num4'),"n":numbers[3]}
    ];
    var timer=null;
    var seconds=3000;//加载时长
    $.fn.extend({
      'runSecond': function () {
        var elem = $(this);
        var h = elem.html()/1;
        var a = 0;
        timer = setInterval(function () {
          if (a <= h) {
            elem.html(a++);
          } else {
//                    clearInterval(timer);
            timer = null;
          }
        }, seconds / h);
      }
    });
    //滚动条滚动到某个位置时开始跑秒
    $(function () {
      var isScroll= 1;
      //min & max
      var limits={
        pc:{'min':50,'max':100},
        wap:{'min':150,'max':250}
      };

      //滚动条滚动到某个位置时开始跑秒
      $(window).scroll(function(){
        function scrollT(){
          if($('body').scrollTop()){
            return $('body').scrollTop();
          }else if($('html').scrollTop()){
            return $('html').scrollTop();
          }else{
            $('document').scrollTop()
          }
        }
        function run(){
          $('.num1').runSecond();
          $('.num2').runSecond();
          $('.num3').runSecond();
          $('.num4').runSecond();
        }
        var scrollTop=scrollT();
        console.log(scrollTop);
        if(w>SCREENlLIMIT){
          if(scrollTop>limits.pc.max&&isScroll%2){
            isScroll++;
            run();
          }
          if(scrollTop<limits.pc.min){
            isScroll=1;
          }
        }else{
          if(scrollTop>limits.wap.max&&isScroll%2){
            isScroll++;
            run();
          }
          if(scrollTop<limits.wap.min){
            isScroll=1;
          }
        }
      });

    });
  </script>
</div>
<p><pre>
&lt;h2>
    &lt;span class="num1">33&lt;/span>
    &lt;span class="num2">113&lt;/span>
    &lt;span class="num3">168&lt;/span>
    &lt;span class="num4">98&lt;/span>
&lt;/h2>
&lt;script>
    /* 主控程序 */
    var w = $(window).width();//当前显示器宽度
    var SCREENlLIMIT=767;
    &lt;!--奔跑数字-->
    var numbers=[33,113,168,98];

    var cons=[
      {"name":$('.num1'),"n":numbers[0]},
      {"name":$('.num2'),"n":numbers[1]},
      {"name":$('.num3'),"n":numbers[2]},
      {"name":$('.num4'),"n":numbers[3]}
    ];
    var timer=null;
    var seconds=3000;//加载时长
    $.fn.extend({
      'runSecond': function () {
        var elem = $(this);
        var h = elem.html()/1;
        var a = 0;
        timer = setInterval(function () {
          if (a &lt;= h) {
            elem.html(a++);
          } else {
//                    clearInterval(timer);
            timer = null;
          }
        }, seconds / h);
      }
    });
    //滚动条滚动到某个位置时开始跑秒
    $(function () {
      var isScroll= 1;
      //min & max
      var limits={
        pc:{'min':50,'max':100},
        wap:{'min':150,'max':250}
      };

      //滚动条滚动到某个位置时开始跑秒
      $(window).scroll(function(){
        function scrollT(){
          if($('body').scrollTop()){
            return $('body').scrollTop();
          }else if($('html').scrollTop()){
            return $('html').scrollTop();
          }else{
            $('document').scrollTop()
          }
        }
        function run(){
          $('.num1').runSecond();
          $('.num2').runSecond();
          $('.num3').runSecond();
          $('.num4').runSecond();
        }
        var scrollTop=scrollT();
        console.log(scrollTop);
        if(w>SCREENlLIMIT){
          if(scrollTop>limits.pc.max&&isScroll%2){
            isScroll++;
            run();
          }
          if(scrollTop&lt;limits.pc.min){
            isScroll=1;
          }
        }else{
          if(scrollTop>limits.wap.max&&isScroll%2){
            isScroll++;
            run();
          }
          if(scrollTop&lt;limits.wap.min){
            isScroll=1;
          }
        }
      });

    });
&lt;/script>
</pre></p>
    </div>
  </section>
</div>
<div class="addHeight"></div>
</body>

</html>
